﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Common.Localization;
using Common.Protocol;
using UI;

namespace Player
{
    using Common.Interfaces;

    using Player.Views;

    public partial class MainWnd : Form
    {
        private ViewBase currentView;

        public MainWnd()
        {
            InitializeComponent();

            this.SetView(new MainView());

            //this.currentView = new MainView();
            //this.currentView.Visible = true;
            //this.currentView.Dock = DockStyle.Fill;
            //this.Controls.Add(this.currentView as UserControl);

            //LocalizationProvider.Language = Language.Ua;
            //this.LocalizationChanged();

            //this.cellContainer.ShowExtendedCell += this.ShowExtendedCell;
        }

        public void SetView(ViewBase view)
        {
            this.Controls.Remove(this.currentView);
            this.currentView = view;
            this.currentView.Dock = DockStyle.Fill;
            this.Controls.Add(this.currentView);
        }

        #region language selection

        private void LocalizationChanged()
        {
            this.currentView.Localize();
        }

        private void LangPictureBoxMouseDown(object sender, MouseEventArgs e)
        {
            (sender as PictureBox).BorderStyle = BorderStyle.FixedSingle;
        }

        private void EnPictureBoxMouseUp(object sender, MouseEventArgs e)
        {
            if (LocalizationProvider.Language != Language.En 
                && this.enPictureBox.BorderStyle == BorderStyle.FixedSingle)
            {
                this.uaPictureBox.BorderStyle = BorderStyle.None;
                this.ruPictureBox.BorderStyle = BorderStyle.None;

                this.ruPictureBox.Top = this.enPictureBox.Top;
                this.uaPictureBox.Top = this.enPictureBox.Top;

                this.ruPictureBox.Height = this.enPictureBox.Height;
                this.uaPictureBox.Height = this.enPictureBox.Height;

                this.ruPictureBox.Width = this.enPictureBox.Width;
                this.uaPictureBox.Width = this.enPictureBox.Width;

                this.enPictureBox.Top -= 1;
                this.enPictureBox.Height += 2;
                this.enPictureBox.Width += 3;

                LocalizationProvider.Language = Language.En;
                this.LocalizationChanged();
            }
        }

        private void RuPictureBoxMouseUp(object sender, MouseEventArgs e)
        {
            if (LocalizationProvider.Language != Language.Ru
                && this.ruPictureBox.BorderStyle == BorderStyle.FixedSingle)
            {
                this.uaPictureBox.BorderStyle = BorderStyle.None;
                this.enPictureBox.BorderStyle = BorderStyle.None;

                this.uaPictureBox.Top = this.ruPictureBox.Top;
                this.enPictureBox.Top = this.ruPictureBox.Top;

                this.uaPictureBox.Height = this.ruPictureBox.Height;
                this.enPictureBox.Height = this.ruPictureBox.Height;

                this.uaPictureBox.Width = this.ruPictureBox.Width;
                this.enPictureBox.Width = this.ruPictureBox.Width;

                this.ruPictureBox.Top -= 1;
                this.ruPictureBox.Height += 2;
                this.ruPictureBox.Width += 3;

                LocalizationProvider.Language = Language.Ru;
                this.LocalizationChanged();
            }
        }

        private void UaPictureBoxMouseUp(object sender, MouseEventArgs e)
        {
            if (LocalizationProvider.Language != Language.Ua
                && this.uaPictureBox.BorderStyle == BorderStyle.FixedSingle)
            {
                this.enPictureBox.BorderStyle = BorderStyle.None;
                this.ruPictureBox.BorderStyle = BorderStyle.None;

                this.enPictureBox.Top = this.uaPictureBox.Top;
                this.ruPictureBox.Top = this.uaPictureBox.Top;

                this.enPictureBox.Height = this.uaPictureBox.Height;
                this.ruPictureBox.Height = this.uaPictureBox.Height;

                this.enPictureBox.Width = this.uaPictureBox.Width;
                this.ruPictureBox.Width = this.uaPictureBox.Width;

                this.uaPictureBox.Top -= 1;
                this.uaPictureBox.Height += 2;
                this.uaPictureBox.Width += 3;

                LocalizationProvider.Language = Language.Ua;
                this.LocalizationChanged();
            }
        }

        private void UaPictureBoxMouseLeave(object sender, EventArgs e)
        {
            if (LocalizationProvider.Language != Language.Ua)
            {
                (sender as PictureBox).BorderStyle = BorderStyle.None;
            }
        }

        private void RuPictureBoxMouseLeave(object sender, EventArgs e)
        {
            if (LocalizationProvider.Language != Language.Ru)
            {
                (sender as PictureBox).BorderStyle = BorderStyle.None;
            }
        }

        private void EnPictureBoxMouseLeave(object sender, EventArgs e)
        {
            if (LocalizationProvider.Language != Language.En)
            {
                (sender as PictureBox).BorderStyle = BorderStyle.None;
            }
        }

        #endregion
    }
}